/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.account.core.repository.entity.AccountLogEntity;
import info.peigen.hotpot.business.account.manage.convertor.AccountLogManageConvertor;
import info.peigen.hotpot.business.account.manage.form.AccountLogManageCreateForm;
import info.peigen.hotpot.business.account.manage.form.AccountLogManageEditForm;
import info.peigen.hotpot.business.account.manage.form.AccountLogManageSearchForm;
import info.peigen.hotpot.business.account.manage.info.AccountLogManageInfo;
import info.peigen.hotpot.business.account.manage.repository.service.AccountLogManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(AccountLogManageService)</b>
 * 管理后台 "账户流水记录" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-08-29
 */
@SuppressWarnings("unused")
@Component
public class AccountLogManageService {
    @Inject
    AccountLogManageRepository accountLogManageRepository;

    public PageResult<AccountLogManageInfo> page(AccountLogManageSearchForm form) {
        LambdaQuery<AccountLogEntity> lambdaQuery = accountLogManageRepository.getMapper().createLambdaQuery()
                .andLike(AccountLogEntity::getAccountLogId, Query.filterLikeEmpty(form.getAccountLogId(), false, true))
                .andLike(AccountLogEntity::getTransLogId, Query.filterLikeEmpty(form.getTransLogId(), false, true))
                .andLike(AccountLogEntity::getTradeId, Query.filterLikeEmpty(form.getTradeId(), false, true))
                .andLike(AccountLogEntity::getTransCode, Query.filterLikeEmpty(form.getTransCode(), false, true))
                .andLike(AccountLogEntity::getAccountId, Query.filterLikeEmpty(form.getAccountId(), false, true))
                .andLike(AccountLogEntity::getDirection, Query.filterLikeEmpty(form.getDirection(), false, true))
                .andLike(AccountLogEntity::getTransTime, Query.filterLikeEmpty(form.getTransTime(), false, true))
                .andLike(AccountLogEntity::getSettleTime, Query.filterLikeEmpty(form.getSettleTime(), false, true))
                .andLike(AccountLogEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return accountLogManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, AccountLogManageConvertor::convertToInfo);
    }

    public void create(AccountLogManageCreateForm form) {
        AccountLogEntity entity = BeanUtil.copyProperties(form, AccountLogEntity.class);
        accountLogManageRepository.save(entity);
    }

    public void edit(AccountLogManageEditForm form) {
        AccountLogEntity entity = BeanUtil.copyProperties(form, AccountLogEntity.class);
        accountLogManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        accountLogManageRepository.delete(id);
    }
}